﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using LogisticsModel;

namespace LogisticsManagementSystem.TruckTeam
{
    public partial class TruckTeamManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptTeamList.DataSource = TruckTeamBLL.GetTruckTeams(0,null);
                rptTeamList.DataBind();

                //绑定下拉框
                ddlTeamNameList.DataSource= TruckTeamBLL.GetTruckTeams(0,null);
                ddlTeamNameList.DataTextField = "TeamName";
                ddlTeamNameList.DataValueField = "TeamID";
                ddlTeamNameList.DataBind();
                ddlTeamNameList.Items.Insert(0, new ListItem("全部", "0"));
            }
        }

        protected void rptTeamList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                LogisticsModel.TruckTeam team = (LogisticsModel.TruckTeam)e.Item.DataItem;

                if (team.TeamID>0)
                {
                    Repeater repeater = (Repeater)e.Item.FindControl("rptTruckList");
                    repeater.DataSource = LogisticsBLL.TruckBLL.GetTruckList(team.TeamID, null, null, 0);
                    repeater.DataBind();
                } 
                
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            int tid = Convert.ToInt32(ddlTeamNameList.SelectedValue);
            string leader = txtLeader.Value;
            rptTeamList.DataSource = LogisticsBLL.TruckTeamBLL.GetTruckTeams(tid, leader);
            rptTeamList.DataBind();
        }
    }
}